package com.xiaocc.spring.demo.csapp;

import java.beans.ConstructorProperties;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;



@Component("abc")
public class CSInitApp {

	public static void main(String[] args) {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring.xml");
		
		System.out.println(applicationContext.getBean("test"));
		System.out.println(applicationContext.getBean("abc"));
		
		System.out.println(applicationContext.getBean("nameInj"));
		
		GETSETBean2 bean2 =  applicationContext.getBean("bean2", GETSETBean2.class);
		System.out.println(bean2.getGetsetBean1());
		
		GETSETBean2 bean3 =  applicationContext.getBean("bean3", GETSETBean2.class);
		System.out.println(bean2.getGetsetBean2());

		System.out.println("============singletom Bean=============");
		for (int i = 0; i < 5; i++) {
			System.out.println(applicationContext.getBean("singletonBean"));
		}
		
		System.out.println("============propertype Bean=============");
		for (int i = 0; i < 5; i++) {
			System.out.println(applicationContext.getBean("propertypeBean"));
		}
		
		System.out.println("============propertype Bean inject into singleton Bean=============");
		for (int i = 0; i < 5; i++) {
			ScopeDemo demo = applicationContext.getBean("singletonBean1", ScopeDemo.class);
			System.out.println(demo.getPropertypeClass());
		}
		
		System.out.println("============Collections property Bean=============");
		
		CollectionsPropertyBean bean = applicationContext.getBean("collectionsPropertyBean", CollectionsPropertyBean.class);
		System.out.println(bean);
		
	}
	
}


class ToStringTest{
	
	
//	这个地方：spring 3.0之后，
//	在基于构造方法的变量名注入，必须：
//	1.设置调试 标识
//	2.在构造方法中使用 ConstructorProperties
	
//	@ConstructorProperties({"", ""})
//	public ToStringTest() {
//		// TODO Auto-generated constructor stub
//	}
	
	private String name;
	
	
	public ToStringTest() {
		// TODO Auto-generated constructor stub
	}
	
	
	public void test() {
		System.out.println("test");
	}
	
	
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
//		return this.toString();
	}
}
